package com.smartboot.plus.controller;

import com.smartboot.plus.api.R;
import com.smartboot.plus.condition.ConditionGroup;
import com.smartboot.plus.condition.ConditionQ;
import com.smartboot.plus.ignite.cache.MqttAuthCache;
import com.smartboot.plus.page.IPage;
import com.smartboot.plus.service.MqttAuthService;
import com.smartboot.plus.support.Condition;
import com.smartboot.plus.support.Query;
import com.smartboot.plus.vo.MqttAuthCacheVO;
import com.smartboot.plus.wapper.MqttAuthWrapper;
import tech.smartboot.feat.cloud.annotation.*;


@Controller("/mqttAuth")
public class AuthController {


    @Autowired
    private MqttAuthService mqttAuthService;


    /**
     * 提交
     */
    @RequestMapping("/submit")
    public R<Object> submit(MqttAuthCache mqttAuthCache) {
        return R.data(mqttAuthService.submit(mqttAuthCache));
    }

    /**
     * 分页
     *
     * @param username
     * @param query
     */
    @RequestMapping("/page")
    public R<IPage<MqttAuthCacheVO>> page(@Param("mqttUsername") String username, Query query) {
        ConditionQ c1 = ConditionQ.like(MqttAuthCache::getUsername, username);
        ConditionGroup conditionGroup = new ConditionGroup().add(c1);
        IPage<MqttAuthCache> mqttAuthCacheIPage = mqttAuthService.selectPage(Condition.getPage(query), conditionGroup, MqttAuthCache.class);
        IPage<MqttAuthCacheVO> mqttAuthCacheVOIPage = MqttAuthWrapper.build().pageVO(mqttAuthCacheIPage);
        return R.data(mqttAuthCacheVOIPage);
    }


    /**
     * 删除
     *
     * @param id
     */
    @RequestMapping("/remove/:id")
    public R<Object> remove(@PathParam("id") String id) {
        return R.status(mqttAuthService.removeId(id));
    }


    /**
     * 修改状态
     *
     * @param id
     * @param status
     */
    @RequestMapping("/status")
    public R<Object> updateStatus(@Param("id") String id, @Param("status") Integer status) {
        return R.status(mqttAuthService.updateStatus(id, status));
    }

}
